<?php

/**
 * Classes pour gérer les requetes
 *
 * PHP version 5
 *
 * LICENSE: GNU General Public License v3
 *
 * @category   Framework
 * @package    Frmaework/Core
 * @author     Mohammed Amine Kaabachi <jedevbien@gmail.com>
 * @copyright  2009 Authentic Development Group
 * @license    GNU General Public License v3
 * @since      File available since Release 0.1.0
 */

class controller
{
    private $_Requests;
    var     $layout;
    var     $use_view               = true;
    private $_HTTPERRORS			= array(400 => "Bad Request",
											401 => "Unauthorized",
											402 => "Payment Required",
											403 => "Forbidden",
											404 => "Not Found",
											405 => "Not Allowed",
											406 => "Not Acceptable",
											407 => "Registration Required",
											408 => "Request Timeout",
											409 => "Conflict",
											500 => "Internal Server Error",
											501 => "Not Implemented",
											502 => "Remove Server Error",
											503 => "Service Unavailable",
											504 => "Remove Server Timeout",
											510 => "Disconnected");

    //fonction (magique), elle est une passerelle entre le framework et le controlleur
    private function __get($var)
    {
        if ($var == "request")
        {
            return $this->_Requests;
        }
        return core::load($var);
    }

    //fonctions pour obtenir les requétes
    public function setRequests($requests)
    {
        $this->_Requests = $requests;
    }


    //fonction par defaut "index"
    function index(){}


    /*
     * @example redirect("home/", 1);
     */
    function redirect($url, $time = 0) {
        if ($time === 0) { // Compatible sans js
            echo '
            <script type="text/javascript">
            window.location="'.$url.'";
            </script>
            <noscript>
            <div align="center"><strong>Redirection....</strong></div>
            <meta http-equiv="refresh" content="1;URL='.$url.'">
            </noscript>
            ';
            die();
         } elseif ($time > 0) {
            $time *= 1000;
            echo '
            <div align="center"><strong>Redirection....</strong></div>
            <script type="text/javascript">
            function redirection(page)
            {window.location=page;}
            setTimeout(\'redirection("'.$url.'/")\','.$time.'); </script>
            <noscript>
            <meta http-equiv="refresh" content="'.$time.';URL='.$url.'">
            </noscript>
            ';
            die();
        } else {
            die('Redirection impossible !');
        }

    }
    //TODO : ajouter une fonction pour gérer les composents
    //TODO : ajouter une fonction qui renvois les helpers
    //TODO : ajouter une fonction qui renvois les elements

}
?>

